/**
 * shilei
 */
define([
    "dojo/_base/declare",
    "gistech/widgets/normalDialog/NormalDialog",
    "dojo/text!./templates/basicBuffer.html",
    "dojo/_base/lang",
    "dojo/topic",
    "dojo/dom-style",
    "dojo/dom-construct",
    "dojo/on",
    "dojo/_base/array",
    "dojo/_base/connect",
    "gistech/util/ajaxUtil",
    "dojo/dom-style","dojo/query","dojo/dom-class",
    "gistech/widgets/FrontHeatDiagram/LandTypeRenderer",
    "esri/layers/FeatureLayer",
    "esri/layers/GraphicsLayer",
    "esri/InfoTemplate",
    "esri/tasks/QueryTask", 
    "esri/tasks/query",
    "esri/tasks/GeometryService",
    "esri/symbols/SimpleLineSymbol",
    "esri/symbols/SimpleFillSymbol",
    "esri/geometry/geometryEngine",
    "esri/tasks/GeometryService",
    "esri/geometry/webMercatorUtils",
    "esri/geometry/geodesicUtils",
    "esri/toolbars/draw",
    "esri/symbols/PictureMarkerSymbol",
    "esri/symbols/SimpleMarkerSymbol",
    "dijit/layout/ContentPane",
    "esri/tasks/BufferParameters", 
    "esri/SpatialReference",
    "esri/graphic",
    "esri/geometry/Point",
    "esri/geometry/Circle",
    "esri/geometry/Polyline",
    "esri/Color"],
    function(declare,NormalDialog,template,lang,Topic,style,domConstruct,on,array,eventconnect,ajaxUtil,domStyle,query,domClass,LandTypeRenderer,FeatureLayer,GraphicsLayer,InfoTemplate,QueryTask,ArcQuery,GeometryService
    		,SimpleLineSymbol,SimpleFillSymbol,geometryEngine,GeometryService,webMercatorUtils,geodesicUtils,Draw,PictureMarkerSymbol,SimpleMarkerSymbol,ContentPane,BufferParameters,SpatialReference,Graphic,Point,Circle,Polyline,Color){
        return declare([NormalDialog],{
        templateString:template,
        container:null,
        constructor:function (args) {
        	this.inherited(arguments);//这个可以不需要
        	this.userPermission={
        			"data":ioc.map.userRoleData,
        			"condition":null,//FQMC in ('南海区','顺德区')
        			"city":{}//{"广州市":[]}
        	},
        	this.trackTrafficSiteLayer={
        		"id":"trackTrafficSite",
        		"url":mapinfoTemplate.GDJTP.layerurl,//轨道站点图层
        		"render":null,
        		"trackSite":null,//符合权限的站点数据
        		"trackTrafficSiteLayer":null,//站点图层
        		"trackTrafficSiteGraphicsLayer":null,//站点graphicsLayer图层
        		"trackTrafficBufferLayer":null,//根据站点生成的缓冲区面图层
        		"bufferMouseoutSym":
        		 new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([255,123,135]), 2),new Color([255,124,0,0.3])),
        		"bufferMouseoverSym":
        		 new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([98,194,204]), 2), new Color([98,194,204,0.3]))
        	},
        	this.trackTrafficLineLayer={
    			"id":"trackTrafficLine",
        		"url":mapinfoTemplate.GDJTL.layerurl,//轨道线路图层
        		"render":null,	
        		"trackTrafficLineLayer":null
        	},
        	this.highWayLineLayer={
        		"url":mapinfoTemplate.HighWay.layerurl,//高速路口
        	},
        	this.highWaySiteLayer={
            	"url":mapinfoTemplate.HighWaySite.layerurl,//轨道站点图层	
        	},
        	this.GDProvData=dsy;
        	/**/
        	this.defineTypeDrawPointBuffer={//自定义类型缓冲区方式
        		"drawTool":new Draw(Global.widgets.mapWidget.map,{tooltipOffset: 20,drawTime: 90}),
        		"pointSym":new PictureMarkerSymbol({"url": "gistech/widgets/bufferWidget/images/lo.png","height": 17,"width":13}),
        		"bufferLayer":null,//根据用户自定义创建的缓冲区面图层
        		"bufferMouseoutSym":
            		new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([255,123,135]), 2),new Color([255,124,0,0.3])),
            	"bufferMouseoverSym":
            		new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([98,194,204]), 2), new Color([98,194,204,0.3]))
        	},
        	this.landType={
                	"纳入三旧的旧厂":{
                		url:mapinfoTemplate.JCFFL3.layerurl,
                		id:"threeOldFactory_buffer",
                		queryFild:"SYQSX",
                		renderColor:"[255,20,147,0.8]",
                		condition:"",
                		templateInfo:mapinfoTemplate.JCFFL3.template,
                		bufferFilterGraphicLayer:null,
                		bufferTableData:{
                			"tabelData":null,
            				"columnsData":null,
            				"sortName":"",
            				"sortOrder":"",
            				"exportTableName":"旧厂房"
                		},
                		arcQuery:new ArcQuery()
                    },
                	"纳入三旧的旧城":{
                		url:mapinfoTemplate.JCHFL3.layerurl,
                		id:"threeOldCity_buffer",
                		queryFild:"SYQSX",
                		renderColor:"[218,165,32,0.8]",
                		condition:"",
                		templateInfo:mapinfoTemplate.JCHFL3.template,
                		bufferFilterGraphicLayer:null,
                		bufferTableData:{
                			"tabelData":null,
            				"columnsData":null,
            				"sortName":"",
            				"sortOrder":"",
            				"exportTableName":"旧城镇"
                		},
                		arcQuery:new ArcQuery()
                	},
                    "国有储备用地":{
                    	url:mapinfoTemplate.JHGD.layerurl,
                    	id:"stateownedReserve_buffer",
                    	queryFild:"YDMJ",
                		renderColor:"[123,104,238,0.8]",
                    	condition:"",
                    	bufferFilterGraphicLayer:null,
                		templateInfo:mapinfoTemplate.JHGD.template,
                		bufferTableData:{
                			"tabelData":null,
            				"columnsData":null,
            				"sortName":"",
            				"sortOrder":"",
            				"exportTableName":"国有储备用地"
                		},
                		arcQuery:new ArcQuery()
                    },
                    "纳入三旧的旧村":{
                    	url:mapinfoTemplate.JCUFL3.layerurl,
                    	id:"threeOldVillage_buffer",
                    	queryFild:"JTMJ",
                    	renderColor:"[0,255,81,0.3]",
                    	condition:"",
                    	bufferFilterGraphicLayer:null,
                		templateInfo:mapinfoTemplate.JCUFL3.template,
                		bufferTableData:{
                			"tabelData":null,
            				"columnsData":null,
            				"sortName":"",
            				"sortOrder":"",
            				"exportTableName":"旧村庄"
                		},
                		arcQuery:new ArcQuery()
                    },
                    "纳入三旧的集体旧厂":{
                    	url:mapinfoTemplate.JCFFL3.layerurl,
                    	queryFild:"SYQSX",
                    	id:"threeOldCollFactory_buffer",
                    	renderColor:"[125,20,113,0.8]",
                    	bufferFilterGraphicLayer:null,
                		templateInfo:mapinfoTemplate.JCFFL3.template,
                		bufferTableData:{
                			"tabelData":null,
            				"columnsData":null,
            				"sortName":"",
            				"sortOrder":"",
            				"exportTableName":"集体旧厂"
                		},
                		arcQuery:new ArcQuery()
                    },
                    "村自留地":{
                    	url:mapinfoTemplate.LYD.layerurl,
                    	id:"villagePlots_buffer",
                    	queryFild:"MJ",
                    	renderColor:"[0,191,255,0.8]",
                    	bufferFilterGraphicLayer:null,
                		templateInfo:mapinfoTemplate.LYD.template,
                		bufferTableData:{
                			"tabelData":null,
            				"columnsData":null,
            				"sortName":"",
            				"sortOrder":"",
            				"exportTableName":"留用地"
                		},
                		arcQuery:new ArcQuery()
                    }
                },
            this.createBufferCondition={//创建缓冲区需要提交的条件
    			"landType":[],
    			"trackTrafficName":"",
    			"trackTrafficLineName":"",
    			"bufferRadius":""
        	},
        	this.staticLandInfo={};//统计地块信息      	
        	this.geometryService=new GeometryService(mapinfoTemplate.geometryServiceUrl);
        	this.blockClickedGraphic=null;//当前点击的Graphic
        	
        	/********基础设施查询***************************/
        	//基础设施查询
        	this.BasicFacilityQuery={
        		url:"http://api.geoq.cn/f9a56ad4ce1ac9c20eba882221703964200aeb4817058bf9a4f69cce3deaceeb/search",
        		cp:null,//查询中心点
        		typecode:"",//类型编码
        		range:"",//查询范围
        		callback:null,
        		result:{
        			"商业配套设施":	{
        				"金融机构":{"购物中心":{typecode:"060101",result:[],"renderColor":[220,20,60,0.8]}}
        			},
        			"教育配套设施":{
        				"学校":{"学校":{typecode:"141200",result:[],"renderColor":[255,140,0,0.8]}},
        				"科研机构":{"科研机构":{typecode:"141300",result:[],"renderColor":[255,140,0,0.8]}},
        				"培训机构":{"培训机构":{typecode:"141400",result:[],"renderColor":[255,140,0,0.8]}},
        				"驾校":{"驾校":{typecode:"141500",result:[],"renderColor":[255,140,0,0.8]}}
        			},
    				"医疗配套设施":{
        				"综合医院":{"综合医院":{typecode:"090100",result:[],"renderColor":[139,0,139,0.8]}},
        			    "诊所":{"诊所":{typecode:"090300",result:[],"renderColor":[139,0,139,0.8]}},
        			    "急救中心":{"急救中心":{typecode:"090400",result:[],"renderColor":[139,0,139,0.8]}},
        			    "疾病预防":{"疾病预防":{typecode:"090500",result:[],"renderColor":[139,0,139,0.8]}},
        			    "医药保健相关":{"医药保健相关":{typecode:"090600",result:[],"renderColor":[139,0,139,0.8]}},
        			    "动物医疗场所":{"动物医疗场所":{typecode:"090700",result:[],"renderColor":[139,0,139,0.8]}}
        			},
    			    "休闲设施":{
        				"婴儿服务场所":{"婴儿服务场所":{typecode:"072000",result:[],"renderColor":[30,144,255,0.8]}},
        				"运动场所":{"运动场所":{typecode:"080100",result:[],"renderColor":[30,144,255,0.8]}},
        				"高尔夫相关":{"高尔夫相关":{typecode:"080200",result:[],"renderColor":[30,144,255,0.8]}},
        				"娱乐场所":{"娱乐场所":{typecode:"080300",result:[],"renderColor":[30,144,255,0.8]}},
        				"度假疗养场所":{"度假疗养场所":{typecode:"080400",result:[],"renderColor":[30,144,255,0.8]}},
        				"休闲场所":{"休闲场所":{typecode:"080500",result:[],"renderColor":[30,144,255,0.8]}},
        				"影剧院相关":{"影剧院相关":{typecode:"080600",result:[],"renderColor":[30,144,255,0.8]}},
        				"公园广场":{"公园广场":{typecode:"110100",result:[],"renderColor":[30,144,255,0.8]}},
        				"风景名胜":{"风景名胜":{typecode:"110200",result:[],"renderColor":[30,144,255,0.8]}}
        			},
    				"厌恶型设施":{
        				"加油站":{"加油站":{typecode:"010100",result:[],"renderColor":[255,0,255,0.8]}},
        				"其它能源站":{"其它能源站":{typecode:"010200",result:[],"renderColor":[255,0,255,0.8]}},
        				"加气站":{"加气站":{typecode:"010300",result:[],"renderColor":[255,0,255,0.8]}},
        				"充电站":{"充电站":{typecode:"011100",result:[],"renderColor":[255,0,255,0.8]}}
        			}
        		},
        		baseFacilityColors:{
        			"商业配套设施":"rgba(220,20,60,0.8)",
        			"教育配套设施":"rgba(255,140,0,0.8)",
        			"医疗配套设施":"rgba(139,0,139,0.8)",
        			"休闲设施":"rgba(30,144,255,0.8)",
        			"厌恶型设施":"rgba(255,0,255,0.8)"
        		},
        		graphicsLayer:new GraphicsLayer({id:"baseFacilityGraphicsLayer"}),
        		currentClickGraphic:null,
        		auxiliarylineLayer:new GraphicsLayer({id:"auxiliarylineGraphicsLayer"})
        	},
        	ioc.map.graphiclayers.push(this.BasicFacilityQuery.graphicsLayer);
        	ioc.map.graphiclayers.push(this.BasicFacilityQuery.auxiliarylineLayer);
        },
        postCreate:function(){
            this.init();
            this.addEvents();
            this.inherited(arguments);//存在继承的话这个就必须得要
        },
        //初始化
        init:function (){
        	Topic.subscribe("bufferBlockInfo",dojo.hitch(this,this._bufferBlockInfo));
        	Topic.subscribe("singleBufferBlockInfoPosition",dojo.hitch(this,this._singleBufferBlockInfoPosition));

        	Topic.subscribe("baseFacilityInfo",dojo.hitch(this,this._baseFacilityInfo));
        	Topic.subscribe("singleBaseFacilityInfo",dojo.hitch(this,this._singleBaseFacilityInfo));
            
        	this._formValidate();//初始化验证
        	this._initFormDomElm();//表单元素初始化
        },
        //添加事件
        addEvents:function(){
        	on(this.basicBufferSaveBtn,"click",lang.hitch(this,this._createBuffer));
        	on(this.basicBufferResetBtn,"click",lang.hitch(this,this._resetBuffer));
        	
        },
        startup:function(){
            this.inherited(arguments);
        },
        /***
         * 验证表单
         */
        _formValidate:function(){
        	$("#basicBufferFormId",this.domNode).validate({
			 	errorElement: 'label',
		        errorClass: 'has-error',
		        focusInvalid: true,
		        rules:{
		        	'landType': {required: true},
		        	'trafficLayerSel':{required: true},
		        	'layerAttrsSel':{required: true},
		        	'bufferRadiusSel':{required: true}
		        },
			    messages:{
			    	'landType': {required: "必填"},
		        	'trafficLayerSel':{required: "必填"},
		        	'layerAttrsSel':{required: "必填"},
		        	'bufferRadiusSel':{required: "必填"}
			    },
		        errorPlacement: function (error, element){
		        	 element.parent().addClass(this.errorClass);
		             element.removeClass(this.errorClass);
		             error.insertAfter(element).css({"margin":"-3px 5px","color":"#a94442","paddingLeft":"22px","width": "50px"});
	            }
			});
        	this._selectChangeValidate();
        	this._inputChangeValidate();
        },
        //select改变后重新验证
		_selectChangeValidate:function(){
			 $('select', $("#basicBufferFormId")).change(function (){
			    	if($("#basicBufferFormId").validate().element($(this))){
			    		$(this).parent().removeClass('has-error');
			    	}
			    });
		},
		//input改变后重新验证
		_inputChangeValidate:function(){
			$('input', $("#basicBufferFormId")).keyup(function (){
		    	if($("#basicBufferFormId").validate().element($(this))){
		    		$(this).parent().removeClass('has-error');
		    	}
		    });
		},
		/**
		 * 表单元素初始化
		 */
		_initFormDomElm:function(){
			this._landTypeFormElmInit();//土地类型元素初始化
			this._bufferTypeFormElmInit();//缓冲区方式表单元素初始化
			//debugger
			this._trackTrafficFormElmInit();//轨道交通元素初始化
			//debugger
		},
		//土地类型元素初始化
		_landTypeFormElmInit:function(){
			//为土地类型绑定单击事件
			var inputItem=$("#landType",this.domNode);
			inputItem.focus(function(){//此时需要给后面的input绑定获取焦点的事件
				//debugger
				require(["gistech/widgets/LandResTree/LandResTree",], function (LandResTree){
					//debugger
					if(!this.landResTree || this.landResTree.isClose){
						this.landResTree = new LandResTree({pos:{l:Math.ceil(document.body.clientWidth)/2-419,t:84},"landTypeItem":inputItem,"formId":"#basicBufferFormId"});
	        		 	this.landResTree.setTitle("土地资源树图表");
	        	 	 	this.landResTree.startup();
					}
        	   });
			}.bind(this));
		},
		//缓冲区方式初始化
		_bufferTypeFormElmInit:function(){
			//debugger
			var $basicBufferSaveBtn=$(this.basicBufferSaveBtn);
			$("input:radio[name=bufferType]",this.domNode).each(function(i,item){
				   $(item).iCheck({
		               checkboxClass: 'icheckbox_flat-green',
		               radioClass: 'iradio_flat-green'
		           });
				   $(item).on('ifChecked', function(){
					   debugger
	        		   $('#trafficLayerSel',this.domNode).val('');
	        		   var option='<option value="">请选择</option>';
						$("#layerAttrsSel",this.domNode).empty();
						$("#layerAttrsSel",this.domNode).append(option);
						$("#layerAttrsSel",this.domNode).attr("disabled","disabled");
					   debugger
					   if($(this).val()	==	"bufferType_define"){
						   $(this).closest(".form-group").prev().show();
						   $(this).closest(".form-group").next().hide();
						   $(this).closest(".form-group").next().next().hide();
						   $basicBufferSaveBtn.text("标绘点");
					   }else if($(this).val() == "baseFacility"){
						   $(this).closest(".form-group").prev().hide();
						   $(this).closest(".form-group").next().hide();
						   $(this).closest(".form-group").next().next().hide();
						   $basicBufferSaveBtn.text("标绘点");
					   }else{
						   $(this).closest(".form-group").prev().show();
						   $(this).closest(".form-group").next().show();
						   $(this).closest(".form-group").next().next().show();
						   $basicBufferSaveBtn.text("确定");
					   }
				   });
			});
		},
		//轨道交通站点表单元素初始化
		_trackTrafficFormElmInit:function(){
			//debugger
			this.userPermission.city={};
			if(this.userPermission.data.length>0){
				//debugger
				if(ioc.map.userInfoData.isManager){//管理员
					array.forEach(this.GDProvData.Items["0"],lang.hitch(this,function(city,idx){
						this.userPermission.city[city]={};
					}));
					var count=0;
					for(var key in this.userPermission.city){
						this.userPermission.city[key]["county"]=this.GDProvData.Items["0_"+ count++];
					}
				}else{//非管理员
					array.forEach(this.userPermission.data,lang.hitch(this,function(item){
						for(var key in this.GDProvData.Items){
							 if(key != "0"){
								 var position = array.indexOf(this.GDProvData.Items[key], item);
								 if(position != -1){
									 var city=this.GDProvData.Items["0"][key.split("_")[1]];
									 
									 if(this.userPermission.city[city] == undefined){
										 this.userPermission.city[city]={"county":[]};
									 }
									 this.userPermission.city[city]["county"].push(item);
									 break;
								 }
							 }
						 }
					}));
					//debugger
				}
				var option='<option value="">请选择</option>';
				for(var key in this.userPermission.city){
					option+='<option value="'+key+'">'+key+'轨道交通</option>';
				}
				//debugger
				$("#trafficLayerSel",this.domNode).empty();
				$("#trafficLayerSel",this.domNode).append(option);
				
				$("#trafficLayerSel",this.domNode).change(function(evt){
					debugger
					this._getcheckedBufferStyle();
					var city=evt.target.value, url="",condition="",field="";
					$('#layerAttrsSel',$(evt.target).closest('.form-group').next()).attr("disabled",true);
					if(city != ""){
						switch(this.checkedBufferStyle){
							case "bufferType_trackSite":
								url=this.trackTrafficLineLayer.url;
								condition="SJMC='"+city+"'";
								field="GDXLMC";
								break;
							case "bufferType_highway":
								url=this.highWayLineLayer.url;
								condition="CSMC='"+city+"'";
								field="BZ2";
								break;
						}
						this._queryTrafficLine(city,url,condition,field);
					}else{
						var option='<option value="">请选择</option>';
						$("#layerAttrsSel",this.domNode).empty();
						$("#layerAttrsSel",this.domNode).append(option);
					}
				}.bind(this));
			}
		},
		_getcheckedBufferStyle:function(){
			var checkedRadioValue="bufferType_trackSite";
    		$("input:radio[name=bufferType]",this.domNode).parent().each(function(i,item){
    			if($(item).hasClass("checked")){
    				checkedRadioValue = $('input:radio',item).val();
    			}
    		});
    		this.checkedBufferStyle=checkedRadioValue;
		},
		//构造查询的区的条件
		_getCountysCondition:function(bufferType){
			if(bufferType == "bufferType_trackSite" || bufferType == "bufferType_highway"){
				var condition="FQMC IN (";
				var countys=this.userPermission.city[this.createBufferCondition["trackTrafficName"]]["county"];
				array.forEach(
		        		countys,function(item, idx, arr){
		    			if(idx == arr.length-1){
		    				return condition+="'"+item+"')";
		    			}else{
		    				return condition+="'"+item+"',";
		    			}
		    		}
		    	);
			}else{
				var condition="";
				if(ioc.map.userInfoData.isManager){
					condition="1=1";
				}else{
					condition="FQMC IN (";
				    array.forEach(this.userPermission.data,function(item, idx, arr){
			    			if(idx == arr.length-1){
			    				return condition+="'"+item+"')";
			    			}else{
			    				return condition+="'"+item+"',";
			    			}
			    	});
				}
			}
			return condition;
		},
		_queryTrafficLine:function(city,url,condition,field){
			//debugger
			var queryTask=new QueryTask(url);//交通轨道线路
			var query=new ArcQuery();
			query.returnGeometry=true;
			query.outFields=["*"];
			query.where=condition;
			queryTask.execute(query,lang.hitch(this,function(trafficLineSet){
				this.userPermission.city[city]["gdxlmc"]={};
				array.forEach(trafficLineSet.features,lang.hitch(this,function(trafficLine){
					this.userPermission.city[city]["gdxlmc"][trafficLine.attributes[field]]={"geometry":null};
					this.userPermission.city[city]["gdxlmc"][trafficLine.attributes[field]]["geometry"]=trafficLine.geometry;
				}));
				var option='<option value="">请选择</option>';
				for(var key in this.userPermission.city[city]["gdxlmc"]){
					option+='<option value="'+key+'">'+key+'</option>';
				}
				//debugger
				$("#layerAttrsSel",this.domNode).empty();
				$("#layerAttrsSel",this.domNode).append(option);
				$("#layerAttrsSel",this.domNode).removeAttr("disabled");
			}));
		},
		/**
		 * 重置缓冲区
		 */
		_resetBuffer:function(){
			this._resetForm();
			this._clearLayerAndTable();
		},
		_resetForm:function(){
			$('#landType',this.domNode).val('');
			$('#trafficLayerSel',this.domNode).val('');
			$('#layerAttrsSel',this.domNode).val('');//这里不用清空，时间已经花了，一个重置10s过去了
			$('#bufferRadiusSel',this.domNode).val('');
		},
		_clearLayerAndTable:function(){
			this._clearTrackTrafficBufferLayer();
			this._clearTrackTrafficSiteGraphicsLayer();
			this._clearLandTypeBufferFilterGraphicLayer();
			this._clearDefineTypeDrawPointBufferLayer();
			this._clearBasicFacilityGraphicsLayer();//清除兴趣点
			this._clearBasicFacilityAuxiliarylineLayer();//清除辅助线图层
			Global.widgets.mapWidget.map.graphics.clear();
			if(Global.widgets.right.hasExpand){
				Global.widgets.right.expandLeft();
				$('.dijitContentPane',Global.widgets.right.domNode).empty();
				if(this.advQueryGraphicLayer!=null){
					this.advQueryGraphicLayer.clear();
				}
			}
		},
		/**
		 * 生成缓冲区
		 */
        _createBuffer:function(){
        	//debugger
        	if(!$("#basicBufferFormId",this.domNode).valid()){
        		return false;
        	}else{
        		//alert("验证通过");
        		debugger
        		this._clearTrackTrafficBufferLayer();
    			this._clearTrackTrafficSiteGraphicsLayer();
    			this._clearLandTypeBufferFilterGraphicLayer();
    			Global.widgets.mapWidget.map.graphics.clear();
    			this._clearDefineTypeDrawPointBufferLayer();
    			this._clearBasicFacilityGraphicsLayer();//清除兴趣点
    			this._clearBasicFacilityAuxiliarylineLayer();//清除辅助线图层
    			
        		this._getBufferCondition();//获取缓冲区表单的元素值
        		this._getcheckedBufferStyle();
        		if(this.checkedBufferStyle == "bufferType_trackSite" || this.checkedBufferStyle == "bufferType_highway"){//轨道站点方式
        			this.userCountyCon=this._getCountysCondition(this.checkedBufferStyle);
        			$("#wrapper").showLoading();
            		this._getLimitConTrafficSite();//获取用户权限内选择的轨道交通线路上的站点
        		}else{//自定义方式
        			this.userCountyCon=this._getCountysCondition(this.checkedBufferStyle);
        			this.defineTypeDrawPointBuffer["drawTool"].activate(Draw.POINT);
        			this.defineTypeDrawPointBuffer["drawTool"].on("draw-end",lang.hitch(this,function(evt){
        				//debugger
        				$("#wrapper").hideLoading();
        				$("#wrapper").showLoading();
        				var drawGraphic=new Graphic(evt.geometry,this.defineTypeDrawPointBuffer["pointSym"]);
        				Global.widgets.mapWidget.map.graphics.add(drawGraphic);
        				if(this.defineTypeDrawPointBuffer.bufferLayer == null){
        					this.defineTypeDrawPointBuffer.bufferLayer=new GraphicsLayer();
        					on(this.defineTypeDrawPointBuffer.bufferLayer, "mouse-over", lang.hitch(this, function(evt){
        	    				evt.graphic.setSymbol(this.defineTypeDrawPointBuffer.bufferMouseoverSym);
        	    			}));
        	    			on(this.defineTypeDrawPointBuffer.bufferLayer, "mouse-out", lang.hitch(this, function(evt){
        	    				evt.graphic.setSymbol(this.defineTypeDrawPointBuffer.bufferMouseoutSym);
        	    			}));
        	    			Global.widgets.mapWidget.map.addLayer(this.defineTypeDrawPointBuffer.bufferLayer,1);
        	    			//存储所有graphic图层
        					ioc.map.graphiclayers.push(this.defineTypeDrawPointBuffer.bufferLayer);
        				}
        				this.defineTypeDrawPointBuffer.bufferLayer.clear();
                		var bufferGeometry=geometryEngine.buffer(evt.geometry,this.createBufferCondition["bufferRadius"]);
        				var graphic =new Graphic(bufferGeometry,this.defineTypeDrawPointBuffer.bufferMouseoutSym);
        				this.defineTypeDrawPointBuffer.bufferLayer.add(graphic);
        				
        				if(this.checkedBufferStyle == "bufferType_define"){
        					this._filterSelLandTypeFeatrueByPolygon(bufferGeometry,"union");
        				}else if(this.checkedBufferStyle == "baseFacility"){
        					debugger
        					if(!Global.widgets.mapWidget.map.getLayer("baseFacilityGraphicsLayer")){
        						Global.widgets.mapWidget.map.addLayer(this.BasicFacilityQuery.graphicsLayer);
        					}
        					if(!Global.widgets.mapWidget.map.getLayer("auxiliarylineGraphicsLayer")){
        						Global.widgets.mapWidget.map.addLayer(this.BasicFacilityQuery.auxiliarylineLayer);
        					}
        					var geo = webMercatorUtils.webMercatorToGeographic(evt.geometry)
        					this.BasicFacilityQuery.cp=geo.y+','+geo.x;
        					this.BasicFacilityQuery.range=$("#bufferRadiusSel",this.domNode).val();
        					Global.widgets.mapWidget.map.setExtent(this.defineTypeDrawPointBuffer.bufferLayer.graphics[0]._extent,true);
        				    debugger
        					this.createAuxiliaryline(evt.geometry);
        					this.queryBaseFacilities();
        				}
                		this.defineTypeDrawPointBuffer["drawTool"].deactivate();
        			}));
        		}
        	}
        },
        //获取表单缓冲区设置的条件
        _getBufferCondition:function(){
        	debugger
        	var landType=[];
        	if($("#landType",this.domNode).closest('.form-group')[0].style.display != "none"){
        		if($("#landType",this.domNode).attr("title")==""){
            		landType.push($("#landType",this.domNode).val().trim());
            	}else{
            		landType=$("#landType",this.domNode).attr("title").split(",");
            		landType = array.map(landType, function(item){
            		      return item.trim();
            		});
            	}
        	}
        	this.createBufferCondition["landType"]=landType;
        	this.createBufferCondition["trackTrafficName"]=$("#trafficLayerSel",this.domNode).val();
        	this.createBufferCondition["trackTrafficLineName"]=$("#layerAttrsSel",this.domNode).val();
        	this.createBufferCondition["bufferRadius"]=$("#bufferRadiusSel",this.domNode).val();
        },
        //获取输入的限制条件下的轨道站点
        _getLimitConTrafficSite:function(){
        	//debugger
        	var trackTrafficLineGeometry = 
        		this.userPermission.city[this.createBufferCondition["trackTrafficName"]]["gdxlmc"][this.createBufferCondition["trackTrafficLineName"]]["geometry"];
        	
        	var siteUrl="";
        	if(this.checkedBufferStyle == "bufferType_trackSite"){
        		siteUrl=this.trackTrafficSiteLayer.url;
        	}else if(this.checkedBufferStyle == "bufferType_highway"){
        		siteUrl=this.highWaySiteLayer.url;
        	}
        	this.trackTrafficSiteLayer.trackTrafficSiteLayer=
    			new FeatureLayer(siteUrl,{id:this.trackTrafficSiteLayer.id,mode:1,outFields:"*"});
        	this.trackTrafficSiteLayer.trackTrafficSiteGraphicsLayer=new GraphicsLayer();
    		Global.widgets.mapWidget.map.addLayer(this.trackTrafficSiteLayer.trackTrafficSiteGraphicsLayer,2);
			ioc.map.graphiclayers.push(this.trackTrafficSiteLayer.trackTrafficSiteGraphicsLayer);//存储所有graphic图层
        	
        	this.userPermission.city[this.createBufferCondition["trackTrafficName"]]["gdxlmc"][this.createBufferCondition["trackTrafficLineName"]]["gdzd"]=[];
        	this.params = new BufferParameters();
        	this.params.distances = [200];
      		this.params.unit = GeometryService.UNIT_METER;
      		this.params.bufferSpatialReference = new SpatialReference({"wkid": 102100});
      		this.params.outSpatialReference = Global.widgets.mapWidget.map.spatialReference;
      		this.params.geometries  = [trackTrafficLineGeometry];
      		this.geometryService.buffer(this.params,lang.hitch(this,function(evt){
      			var query=new ArcQuery();
      			query.geometry=evt[0];
      			//query.where=this.userCountyCon;
      			this.trackTrafficSiteLayer.trackTrafficSiteLayer.selectFeatures(query,FeatureLayer.SELECTION_NEW,lang.hitch(this,function(results){
      				if(results.length !=0){
          				var results= array.map(results, function(result){
            			     return result.geometry;
  	          			});
  	          			//debugger
  	          			array.forEach(results,lang.hitch(this,function(geometry){
  	          		     	var graphic=null,pointSym=null;
  	          				if(this.checkedBufferStyle == "bufferType_highway"){
  	          					pointSym=new PictureMarkerSymbol({"url": "gistech/widgets/bufferWidget/images/gs.png","height": 17,"width":13});
  	          				}else{
  	          					pointSym=new PictureMarkerSymbol({"url": "gistech/widgets/bufferWidget/images/subway.png","height": 17,"width":13});
	          				}
  	          				graphic=new Graphic(geometry,pointSym);
  	          				this.trackTrafficSiteLayer.trackTrafficSiteGraphicsLayer.add(graphic);
  	          			}));
  	          			this.userPermission.city[this.createBufferCondition["trackTrafficName"]]["gdxlmc"][this.createBufferCondition["trackTrafficLineName"]]["gdzd"]
  	          			=this.userPermission.city[this.createBufferCondition["trackTrafficName"]]["gdxlmc"][this.createBufferCondition["trackTrafficLineName"]]["gdzd"].concat(results);
  	          			//debugger
  	              		this._createSiteBuffer();//创建站点的缓冲区
  	              		this._bufferUnion();//将所有的缓冲区合并 并 使用多边形面与选择的图层做交集
          			}else{
          				$("#wrapper").hideLoading();
          				Arcdialog.tips('该轨道线上未找到站点数据!',Math.ceil(document.body.clientWidth)/2-75,80,150,50,1);
          				return;
          			}
      			}));
      		}));
        },
        //创建轨道站点缓冲区
        _createSiteBuffer:function(){
        	//debugger
        	if(this.trackTrafficSiteLayer.trackTrafficBufferLayer == null){
        		this.trackTrafficSiteLayer.trackTrafficBufferLayer=new GraphicsLayer();
        		on(this.trackTrafficSiteLayer.trackTrafficBufferLayer, "mouse-over", lang.hitch(this, function(evt){
    				evt.graphic.setSymbol(this.trackTrafficSiteLayer.bufferMouseoverSym);
    			}));
    			on(this.trackTrafficSiteLayer.trackTrafficBufferLayer, "mouse-out", lang.hitch(this, function(evt){
    				evt.graphic.setSymbol(this.trackTrafficSiteLayer.bufferMouseoutSym);
    			}));
    			on(this.trackTrafficSiteLayer.trackTrafficBufferLayer, "click", lang.hitch(this, function(evt){
    				//debugger
    				this._filterSelLandTypeFeatrueByPolygon(evt.graphic.geometry,"single");
    			}));
    			Global.widgets.mapWidget.map.addLayer(this.trackTrafficSiteLayer.trackTrafficBufferLayer,1);
    			//存储所有graphic图层
				ioc.map.graphiclayers.push(this.trackTrafficSiteLayer.trackTrafficBufferLayer);
        	}
        	this.trackTrafficSiteLayer.trackTrafficBufferLayer.clear();
        	if(this.defineTypeDrawPointBuffer.bufferLayer != null){
        		this.defineTypeDrawPointBuffer.bufferLayer.clear();
        	}
        	var siteGeometryArr=this.userPermission.city[this.createBufferCondition["trackTrafficName"]]["gdxlmc"][this.createBufferCondition["trackTrafficLineName"]]["gdzd"];
        	array.forEach(siteGeometryArr,lang.hitch(this,function(siteGeometry){
        		//debugger
        		var polygon=geometryEngine.buffer(siteGeometry,this.createBufferCondition["bufferRadius"]);//这里就不需要转了本身就是投影坐标
        		var graphic =new Graphic(polygon,this.trackTrafficSiteLayer.bufferMouseoutSym);
        		this.trackTrafficSiteLayer.trackTrafficBufferLayer.add(graphic);
        	}));
        },
        //将生成的缓冲区多边形合并为一个,并根据合并的多边形进行土地类型要素的过滤
        _bufferUnion:function(){
        	//debugger
        	var bufferGraphs=this.trackTrafficSiteLayer.trackTrafficBufferLayer.graphics;
        	var bufferGeometrys;
        	bufferGeometrys=array.map(bufferGraphs, function(bufferGraph){
        	      return bufferGraph.geometry;
        	});
        	this.geometryService.union(bufferGeometrys, lang.hitch(this,function(union){
        		//debugger
        		this._filterSelLandTypeFeatrueByPolygon(union,"union");
        	}));
        },
        //根据面积过滤 土地类型图层数据
        _filterSelLandTypeFeatrueByPolygon:function(polygon,flag){
        	//debugger
        	if(flag=="union"){
        		this._clearLandTypeBufferFilterGraphicLayer();//清除之前查询出的土地用地类型graphic图层中的graphic对象
        	}
        	//debugger
        	this.count=0;
        	this.staticLandInfo={};//统计选中的地块的信息数据
        	this._filterFeature(this.createBufferCondition["landType"][0],polygon);
        },
        _filterFeature:function(langTypeName,polygon){
        		this._arcQueryFillAttr(langTypeName,polygon);
        		this._createAndClearGraphicsLayer(langTypeName);
        		var landTypeFeature = new FeatureLayer(this.landType[langTypeName]["url"],{mode:1,outFields:"*"});
            	landTypeFeature.selectFeatures(this.landType[langTypeName]["arcQuery"],FeatureLayer.SELECTION_NEW,lang.hitch(this,function(queryResults){
    				this._getTableDataAndFillGraphicsLayer(langTypeName,queryResults);
    				this._staticLandInfo(langTypeName,queryResults);
    				this.count++;
    				if(this.count < this.createBufferCondition["landType"].length){
    					this._filterFeature(this.createBufferCondition["landType"][this.count],polygon);
    				}
    				if(this.count == this.createBufferCondition["landType"].length){
    					Global.widgets.mapWidget.map.setExtent(polygon.getExtent(), true);
    					this._tableDataFill();
        				$("#wrapper").hideLoading();
    				}
            	}));
        },
        _arcQueryFillAttr:function(langTypeName,polygon){
        	this.landType[langTypeName]["arcQuery"].geometry=polygon;
    		this.landType[langTypeName]["arcQuery"].where=this.userCountyCon;
    		if(langTypeName == '纳入三旧的旧厂' || langTypeName == '纳入三旧的旧城'){
    			this.landType[langTypeName]["arcQuery"].where += " AND "+this.landType[langTypeName]["queryFild"]+"='国有用地'";
        	}else if(langTypeName == '纳入三旧的集体旧厂'){
        		this.landType[langTypeName]["arcQuery"].where += " AND "+this.landType[langTypeName]["queryFild"]+"='集体用地'";
        	}else{
        		this.landType[langTypeName]["arcQuery"].where += " AND "+this.landType[langTypeName]["queryFild"]+"<>0";
        	}
        },
        _createAndClearGraphicsLayer:function(langTypeName){
        	if(this.landType[langTypeName].bufferFilterGraphicLayer == null){
				this.landType[langTypeName].bufferFilterGraphicLayer= new GraphicsLayer({
					id:this.landType[langTypeName].id,
					infoTemplate:new InfoTemplate(this.landType[langTypeName].templateInfo)
				});
				this.landType[langTypeName].bufferFilterGraphicLayer.setRenderer(new LandTypeRenderer({config:{color:this.landType[langTypeName].renderColor}}));
				Global.widgets.mapWidget.map.addLayer(this.landType[langTypeName].bufferFilterGraphicLayer,2);
				//存储所有graphic图层
				ioc.map.graphiclayers.push(this.landType[langTypeName].bufferFilterGraphicLayer);
        	}
        },
        _getTableDataAndFillGraphicsLayer:function(langTypeName,queryResults){
        	//debugger
        	this.landType[langTypeName]["bufferTableData"]["tabelData"]=[];
			this.landType[langTypeName]["bufferTableData"]["columnsData"]=this._bufferBlockColumsData(langTypeName);
			array.forEach(queryResults,lang.hitch(this,function(result){
				this.landType[langTypeName].bufferTableData.tabelData.push(this._bufferBlockDataObj(langTypeName,result.attributes));
				this.landType[langTypeName].bufferFilterGraphicLayer.add(new Graphic(result.geometry,null,result.attributes));
			}));
        },
        //统计用地信息
        _staticLandInfo:function(langTypeName,results){
        	//debugger
        	this.staticLandInfo[langTypeName]={landName:langTypeName,landNums:0,area:0};
			this.staticLandInfo[langTypeName].landNums=results.length;
			array.forEach(results,lang.hitch(this,function(result){
				//根据多边形自己计算的
				/*var geo = webMercatorUtils.webMercatorToGeographic(result.geometry);
    			this.staticLandInfo[langTypeName].area += Math.abs(geodesicUtils.geodesicAreas([geo], esri.Units.SQUARE_METERS));*/
				//将属性用地面积相加
				switch(langTypeName){
					case "纳入三旧的旧厂":
					case "纳入三旧的旧城":
					case "纳入三旧的旧村":
					case "纳入三旧的集体旧厂":
					case "国有储备用地":
						this.staticLandInfo[langTypeName].area += result.attributes.YDMJ;
						break;
					case "村自留地":
						this.staticLandInfo[langTypeName].area += result.attributes.MJ;
						break;
				}
			}));
			this.staticLandInfo[langTypeName].area=this.staticLandInfo[langTypeName].area.toFixed(2);
        },
        //进行表格数据的填充
        _tableDataFill:function(){
        	//将左侧组件展开
			if(!Global.widgets.right.hasExpand){
				Global.widgets.right.expandLeft();
			}
			Global.widgets.right.removeAllTab();
			var tableParam={
				"tableData":this._tableData(),
				"columnsData":this._tableColumnsData(),
				"sortName":'',
				"sortOrder":''
			};
			var bootstrapTableParamSetting={detailView:false,search:false,showExport:false,showToggle:false};
			var tableTitle="土地统计信息列表";
			this._createTable(tableParam,bootstrapTableParamSetting,tableTitle);
        },
        _createTable:function(tableParam,bootstrapTableParamSetting,tableTitle,callbackFun){
        	require(["gistech/widgets/QueryTableList/QueryTableList"],lang.hitch(this,function(QueryTableList){
        		//debugger
				var queryTableList = new QueryTableList(tableParam);
        		queryTableList.$table.bootstrapTable('refreshOptions',bootstrapTableParamSetting);
				queryTableList.startup();
				if($(Global.widgets.right.domNode).children(".queryList").length!=0){
					$(Global.widgets.right.domNode).children(".queryList").remove();
				}
				//为table添加标题信息--定制化
				$('.fixed-table-toolbar',queryTableList.domNode).css({"height":"42px","background-color":"#f5f5f5","margin-bottom":"5px","padding-top":"10px","border-radius": "4px","margin-top": "6px"});
				var headHTML='<span style="font-size: 16px;padding-left: 10px;">'+tableTitle+'</span>';
				domConstruct.place(headHTML, $('.fixed-table-toolbar',queryTableList.domNode)[0], "first");
				$('.fixed-table-toolbar .columns',queryTableList.domNode).css({"margin-top":"-5px","margin-right":"10px"});
				
				if(queryTableList.$table.bootstrapTable('getOptions').search){//带搜索的
					$('.fixed-table-toolbar .search',queryTableList.domNode).css({"margin-top":"-28px","margin-left": "158px"});
				}else{
					$('.fixed-table-container .pagination-detail',queryTableList.domNode).css("display","none");
				}
				if(!ioc.map.userInfoData.isManager){
					$('.fixed-table-toolbar .columns .export',queryTableList.domNode).css("display","none");
				}
				
				var panel = new ContentPane();
				$(panel.domNode).wrapInner(queryTableList.domNode);
				if($('.centerPanel>.dijitContentPane>:nth-child(2)',Global.widgets.right.domNode).length == 1){
					$('.centerPanel>.dijitContentPane>:nth-child(2)',Global.widgets.right.domNode).remove();
				}
				Global.widgets.right.addTab(panel);
				
				//调整搜索框的位置
				var centerPanel=$('.centerPanel',Global.widgets.right.domNode)[0];
				var scrollWidth=centerPanel.offsetWidth-centerPanel.scrollWidth;
				if($('.centerPanel>.dijitContentPane>:nth-child(2)',Global.widgets.right.domNode).length == 1){
					$('.centerPanel>.dijitContentPane>:nth-child(2) .fixed-table-toolbar .search',Global.widgets.right.domNode).css("margin-left",158-scrollWidth+'px');
				}
				if(callbackFun && (typeof callbackFun ==='function')){
					callbackFun(queryTableList);//执行一些特殊的操作
				}
			}));
        },
        _tableColumnsData:function(){
        	var arr=[
			 {field:'landName',title:'土地类型名称',width:30,align:'center'},
             {field:'landNums',title:'宗数(块)',width:40,align:'center'},
             {field:'area',title:'用地面积(/平方米)', width:30,align:'center'}]
  			return arr;
		},
		_tableData:function(){
			var arr=[];
			for(var key in this.staticLandInfo){
				var obj={};
				for(var key1 in this.staticLandInfo[key]){
					obj[key1]=this.staticLandInfo[key][key1];
				}
				arr.push(obj);
			}
			return arr;
		},
		//缓冲区地块列数据
		_bufferBlockColumsData:function(landTypeName){
			//debugger
			var arr=[
	           {field:'OBJECTID',title:'地块ID',width:30,align:'center',visible:false},
			   {field:'CODE',title:'要素代码',width:30,align:'center',sortable:true,visible:false},
               {field:'CSMC',title:'市',width:40,align:'center',visible:false},
               {field:'FQMC',title:'区/县', width:30,align:'center',visible:false}];
			switch(landTypeName){
				case "纳入三旧的旧厂":
				case "纳入三旧的旧城":
				case "纳入三旧的旧村":
				case "纳入三旧的集体旧厂":
					var SJArr=[
					    {field:'ZJMC',title:'镇街名称',width:30,align:'center',visible:true},
					    {field:'ZLDWMC',title:'座楼单位名称',width:30,align:'center',visible:true}, 
					    {field:'YDMJ',title:'用地面积',width:30,align:'center',visible:true},
					    {field:'QSDWMC',title:'权属单位',width:30,align:'center',visible:true},
					    {field:'XMDKBH',title:'图斑编号',width:30,align:'center',visible:false}, 
					    {field:'GZLX',title:'改造类型',width:30,align:'center',visible:false}, 
					    {field:'SYQSX',title:'所有权属性',width:30,align:'center',visible:false},
					    {field:'TDYT',title:'现土地用途',width:30,align:'center',visible:false},
					    {field:'GHYT',title:'规划用途',width:30,align:'center',visible:false},
					    {field:'NGZYT',title:'拟改造用途',width:30,align:'center',visible:false},
					    {field:'SFBZGH',title:'是否规划',width:30,align:'center',visible:false},
					    {field:'GYMJ',title:'其中国有面积',width:30,align:'center',visible:false},
					    {field:'JTMJ',title:'其中集体面积',width:30,align:'center',visible:false},
					    {field:'NYDMJ',title:'其中农用地面积',width:30,align:'center',visible:false},
					    {field:'HFYDMJ',title:'其中合法用地面积',width:30,align:'center',visible:false},
					    {field:'JHGZNF',title:'计划改造年份',width:30,align:'center',visible:false},
					    {field:'BZ',title:'备注',width:30,align:'center',visible:false},
					    {field:'BZ2',title:'标注',width:30,align:'center',visible:false},
					    {field:'JCFNF',title:'旧村庄年份',width:30,align:'center',visible:false}
					];
					arr	= arr.concat(SJArr);
					break;
				case "村自留地":
					var lydArr=[//留用地
					    {field:'ZJMC',title:'镇街名称',width:30,align:'center',visible:true},
					    {field:'CMC',title:'村（社区）名称',width:30,align:'center',visible:true},
					    {field:'MJ',title:'面积',width:30,align:'center',visible:true},
					    {field:'QSDW',title:'权属单位',width:30,align:'center',visible:true},
					    {field:'SYQXZ',title:'所有权性质',width:30,align:'center',visible:false},
					    {field:'XZYT',title:'现状用途',width:30,align:'center',visible:false},
					    {field:'DZ',title:'地址',width:30,align:'center',visible:false},
					    {field:'WH',title:'选址文号',width:30,align:'center',visible:false},
					    {field:'PWH',title:'土地发证文号',width:30,align:'center',visible:false},
					    {field:'BZ',title:'备注',width:30,align:'center',visible:false},
					    {field:'BZ2',title:'标注',width:30,align:'center',visible:false}
					];
					arr	= arr.concat(lydArr);
					break;
				case "国有储备用地":
					var jhgdArr=[//国有储备用地
					     {field:'ZJMC',title:'镇街名称',width:30,align:'center'},
					     {field:'YDMJ',title:'用地面积',width:30,align:'center'},
			             {field:'SJMC',title:'市界名称',width:30,align:'center',visible:false},
			             {field:'QJMC',title:'区界名称',width:30,align:'center',visible:false},
			             {field:'BZ',title:'备注',width:30,align:'center',visible:false},
			             {field:'BZ2',title:'标注',width:30,align:'center',visible:false}
					];
					arr	= arr.concat(jhgdArr);
					break;
			}
			return arr;
		},
		//缓冲区地块数据对象
		_bufferBlockDataObj :function(landTypeName,attr){
				//debugger
				var obj={};
				obj['OBJECTID']=attr.OBJECTID;
				obj["CODE"] = attr.CODE;
				obj["CSMC"] = attr.CSMC;
				obj["FQMC"] = attr.FQMC;
				switch(landTypeName){
					case "纳入三旧的旧厂":
					case "纳入三旧的旧城":
					case "纳入三旧的旧村":
					case "纳入三旧的集体旧厂":
						obj["ZJMC"] =   attr.ZJMC;
						obj["ZLDWMC"] = attr.ZLDWMC;
						obj["YDMJ"] =   attr.YDMJ.toFixed(2);
						obj["QSDWMC"] = attr.QSDWMC;
						obj["XMDKBH"] = attr.XMDKBH;
						obj["GZLX"] =   attr.GZLX;
						obj["SYQSX"] =  attr.SYQSX;
						obj["TDYT"] =   attr.TDYT;
						obj["GHYT"] =   attr.GHYT;
						obj["NGZYT"] =  attr.NGZYT;
						obj["SFBZGH"] = attr.SFBZGH;
						obj["GYMJ"] =   attr.GYMJ;
						obj["JTMJ"] =   attr.JTMJ;
						obj["NYDMJ"] =  attr.NYDMJ;
						obj["HFYDMJ"] = attr.HFYDMJ;
						obj["JHGZNF"] = attr.JHGZNF;
						obj["BZ"] =     attr.BZ;
						obj["BZ2"] =    attr.BZ2;
						obj["JCFNF"] =  attr.JCFNF;
						break;
					case "村自留地":
						obj["ZJMC"] =  attr.ZJMC;
						obj["CMC"] =   attr.CMC;
						obj["MJ"] =    attr.MJ.toFixed(2);
						obj["QSDW"] =  attr.QSDW;
						
						obj["SYQXZ"] = attr.SYQXZ;
						obj["XZYT"] =  attr.XZYT;
						obj["DZ"] =    attr.DZ;
						obj["ZJMC"] =  attr.ZJMC;
						obj["WH"] =    attr.WH;
						obj["PWH"] =   attr.PWH;
						obj["BZ"] =    attr.BZ;
						obj["BZ2"] =   attr.BZ2;
						break;
					case "国有储备用地":
						obj["ZJMC"] = attr.ZJMC;
						obj["YDMJ"] = attr.YDMJ.toFixed(2);
						
						obj["SJMC"] = attr.SJMC;
						obj["QJMC"] = attr.QJMC;
						obj["BZ"] = attr.BZ;
						obj["BZ2"] = attr.BZ2;
						break;
				}
			return obj;
		},
		//缓冲区地块详细信息
		_bufferBlockInfo:function(paramObj){
			if(paramObj.landName != undefined){
				//debugger
				var tableParam={
					"tableData":this.landType[paramObj["landName"]]["bufferTableData"]["tabelData"],
					"columnsData":this.landType[paramObj["landName"]]["bufferTableData"]["columnsData"],
					"sortName":'',
					"sortOrder":'',
					"exportTableName":this.landType[paramObj["landName"]]["bufferTableData"]["exportTableName"]
				};
				var bootstrapTableParamSetting={};
				var tableTitle= paramObj["landName"];
				this._createTable(tableParam,bootstrapTableParamSetting,tableTitle);
			}
		},
		_singleBufferBlockInfoPosition:function(paramObj){
			//debugger
			if(paramObj.blockInfoById != undefined){
				//debugger
				//首先确定是那个图层
				var landTypeName="";
				$('.centerPanel>.dijitContentPane>:nth-child(1) table>tbody>tr',Global.widgets.right.domNode).each(function(i,val){
					if($(val).css("backgroundColor") == "rgb(255, 252, 204)"){
						landTypeName=$('td:nth-child(1)',val).text();
					}
				});
				//debugger
				var garphics =this.landType[landTypeName].bufferFilterGraphicLayer.graphics,
				color = this.landType[landTypeName]["renderColor"],
				line,symbol;
				for(var i in garphics){
					if(garphics[i].attributes["OBJECTID"]==paramObj["blockInfoById"]){
						if(this.blockClickedGraphic!=null){
							//还原该graphic的渲染
							color = color.substring(color.indexOf("[")+1, color.indexOf("]"));
							var colorArr=color.split(",");
							line=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,255,255,0.3]), 1);
							symbol=new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,line,new dojo.Color([parseInt(colorArr[0]),parseInt(colorArr[1]),parseInt(colorArr[2]),parseFloat(colorArr[3])]));
							this.blockClickedGraphic.setSymbol(symbol);
						}
						//对该graphic进行渲染
						line=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,255,255,1]), 3);
						symbol=new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,line,this.landType[landTypeName].bufferFilterGraphicLayer.renderer.getSymbol().color);
						garphics[i].setSymbol(symbol);
						Global.widgets.mapWidget.map.centerAndZoom(garphics[i].geometry.getCentroid(), 11);
						this.blockClickedGraphic=garphics[i];
						break;
					}
				}
			}
		},
        //清除轨道站点缓冲图层
		_clearTrackTrafficBufferLayer:function(){
			if(this.trackTrafficSiteLayer.trackTrafficBufferLayer != null){
				this.trackTrafficSiteLayer.trackTrafficBufferLayer.clear();
			}
		},
		//清除轨道站点图层
		_clearTrackTrafficSiteLayer:function(){
			if(this.trackTrafficSiteLayer.trackTrafficSiteLayer != null){
				this.trackTrafficSiteLayer.trackTrafficSiteLayer.clear();
			}
		},
		_clearTrackTrafficSiteGraphicsLayer:function(){
			if(this.trackTrafficSiteLayer.trackTrafficSiteGraphicsLayer != null){
				this.trackTrafficSiteLayer.trackTrafficSiteGraphicsLayer.clear();
			}
		},
		//清除过滤的土地类型图层
        _clearLandTypeBufferFilterGraphicLayer:function(){
        	for(var key in this.landType){
        		if(this.landType[key]["bufferFilterGraphicLayer"] !=null){
        			this.landType[key]["bufferFilterGraphicLayer"].clear();
        		}
        	}
        },
        //清除自定义画点的缓冲区图层
        _clearDefineTypeDrawPointBufferLayer:function(){
        	if(this.defineTypeDrawPointBuffer.bufferLayer != null){
        		this.defineTypeDrawPointBuffer.bufferLayer.clear();
        	}
        },
        onClose:function(){
        	$(this.domNode).hide();
        },
        /**
         * 查询基础设施数据
         */
        queryBaseFacilities:function(){
        	//debugger
        	var typeCodes=[],asyResponseCount=0;
        	for(var obj in this.BasicFacilityQuery.result){
        		for(var obj1 in this.BasicFacilityQuery.result[obj]){
        			for(var key in this.BasicFacilityQuery.result[obj][obj1]){
        				typeCodes.push(this.BasicFacilityQuery.result[obj][obj1][key]["typecode"]);
        			}
        		}
        	}
        	$.each(typeCodes,function(i,item){
        		this.BasicFacilityQuery.typecode=item;
        		this.toSearch(function(resp,typecode){
        			//debugger
    				for(var obj in this.BasicFacilityQuery.result){
    	        		for(var obj1 in this.BasicFacilityQuery.result[obj]){
    	        			for(var key in this.BasicFacilityQuery.result[obj][obj1]){
    	        				if(this.BasicFacilityQuery.result[obj][obj1][key]["typecode"] == typecode){
    	        					if(resp.results && resp.results.length != 0){
    	        						this.BasicFacilityQuery.result[obj][obj1][key]["result"]=resp.results;
        	        					var renderColor=this.BasicFacilityQuery.result[obj][obj1][key]["renderColor"];
        	        					this.pointDrawMap(renderColor,resp.results);//将查询的结果绘制到地图上
    	        					}else{
    	        						this.BasicFacilityQuery.result[obj][obj1][key]["result"]=[];
    	        					}
    	        					break;
    	        				}
    	        			}
    	        		}
    	        	}
        			asyResponseCount++;
        		    if(asyResponseCount == typeCodes.length){//此时全部都查询完成
        		    	$("#wrapper").hideLoading();
        		    	this.baseFacilitiesTableList();
        		    	this.baseFacilitiesDetailTableData("商业配套设施");
        		    }
        		}.bind(this));
        	}.bind(this));
        },
        toSearch:function(callback){
        	//debugger
        	var url='proxy.jsp?'+this.BasicFacilityQuery.url+'?cp='+this.BasicFacilityQuery.cp+'&range='+this.BasicFacilityQuery.range+'&typecode='+this.BasicFacilityQuery.typecode+'&f=json';
        	var  typecode=this.BasicFacilityQuery.typecode;
        	(function(typecode,url){
        		$.ajax({
            		type:"GET",
            		url:url,
            		success:function(resp){
            			//debugger
            			callback(resp,typecode);
            		}
            	});
        	})(typecode,url)
        },
        pointDrawMap:function(color,results){
        	$.each(results,function(i,item){
        		 var pt = new Point(item.lon, item.lat, new SpatialReference({ wkid: 4326 }));
        		  var sms = new SimpleMarkerSymbol().setStyle(SimpleMarkerSymbol.STYLE_CIRCLE).setColor(new Color(color));
        		  var attr = {"objectid":item.objectid,"name":item.name,"address":item.address,"typename":item.typename,"telephone":item.telephone};
        		  var infoTemplate = new InfoTemplate("<p>${name}</p>","<table style='font-size:13px;' class='layerInfo'>"
			        +"<tr><td>名称</td><td>${name}</td></tr>"
				    +"<tr><td style='width:60px;'>地址</td><td>${address}</td></tr>"
				    +"<tr><td>类型</td><td>${typename}</td></tr>"
				    +"<tr><td>联系电话</td><td >${telephone}</td></tr>");
        		  var graphic = new Graphic(pt,sms,attr,infoTemplate);
        		  graphic.symbol.outline.setColor(new Color([255,255,255,0]));
        		  this.BasicFacilityQuery.graphicsLayer.add(graphic);
        	}.bind(this));
        },
        baseFacilitiesTableList:function(){
        	Global.widgets.right.removeAllTab();
			var columnArr=[
			   {field:'id',title:'编号',width:30,align:'center'},
			   {field:'baseFacilityName',title:'设施名称',width:30,align:'center'},
			   {field:'count',title:'数量',width:40,align:'center'}
	        ];
			var dataArr=[],i=0;
			debugger
			for(var key in this.BasicFacilityQuery.result){
				debugger
				var obj={};
				obj["id"] = ++i;
				obj["baseFacilityName"]=key;
				obj["count"]=0;
				for(var key1 in this.BasicFacilityQuery.result[key]){
					for(var key2 in this.BasicFacilityQuery.result[key][key1]){
						obj["count"]+=this.BasicFacilityQuery.result[key][key1][key2]["result"].length;
					}
				}
				dataArr.push(obj);
			}
			var tableParam={
				"tableData":dataArr,
				"columnsData":columnArr,
				"sortName":'',
				"sortOrder":''
			};
			//debugger
			var bootstrapTableParamSetting={detailView:false,search:false,showExport:false,showToggle:false};
			var tableTitle="基础设施列表";
			this._createTable(tableParam,bootstrapTableParamSetting,tableTitle,function(queryTableList){
				//debugger
				$('tbody>tr:nth-child(1)',queryTableList.domNode).css("backgroundColor","#fffccc").unbind();
				queryTableList.selRow.selRowElement=$('tbody>tr:nth-child(1)',queryTableList.domNode);
				
				$.each($('table tr>td:nth-child(2)',queryTableList.domNode),function(i,item){
					var color;
					for(var key in this.BasicFacilityQuery.baseFacilityColors){
						if($(item).text() == key){
							color= this.BasicFacilityQuery.baseFacilityColors[key];
						}
					}
					$(item).prepend("<div style='position: absolute;width: 15px;height: 15px;border-radius: 60%;margin-left: 25px;background-color:"+color+"'></div>");
				}.bind(this));
				this.setRightToolsPosition();
			}.bind(this));
        },
        baseFacilitiesDetailTableData:function(baseFacilityName){
        	var columnArr=[
               {field:'singBaseFacilityName',title:'名称',width:20,align:'center'},
			   {field:'typename',title:'类别',width:30,align:'center'},
			   {field:'address',title:'地址',width:80,align:'center'},
			   {field:'telephone',title:'联系电话',width:30,align:'center'},
			   {field:'objectid',title:'唯一标识',width:30,align:'center',visible:false},
        	];
        	var dataArr=[];
        	for(var key in this.BasicFacilityQuery.result[baseFacilityName]){
        		for(var key1 in this.BasicFacilityQuery.result[baseFacilityName][key]){
        			var result = this.BasicFacilityQuery.result[baseFacilityName][key][key1]["result"];
        			//debugger
        			$.each(result,function(i,item){
        				var obj={};
        				obj["singBaseFacilityName"] = item.name;
        				obj["typename"]= item.typename;
        				obj["address"]= item.address;
        				obj["telephone"]= item.telephone;
        				obj["objectid"]= item.objectid;
        				dataArr.push(obj);
        			}.bind(this))
        		}
        	}
        	var tableParam={
				"tableData":dataArr,
				"columnsData":columnArr,
				"sortName":'',
				"sortOrder":'',
				"exportTableName":baseFacilityName
			};
			var bootstrapTableParamSetting={detailView:true,search:true,showExport:true,showToggle:true};
			var tableTitle=baseFacilityName;
			this._createTable(tableParam,bootstrapTableParamSetting,tableTitle);
        },
        _baseFacilityInfo:function(obj){
        	//debugger
        	if(obj.baseFacilityName != undefined){
        		this.baseFacilitiesDetailTableData(obj.baseFacilityName);
        	}
        },
        _singleBaseFacilityInfo:function(obj){
        	//debugger
        	if(obj.singBaseFacilityId != undefined){
        		var graphics= Global.widgets.mapWidget.map.getLayer("baseFacilityGraphicsLayer").graphics;
        		if(this.BasicFacilityQuery.currentClickGraphic){
        			this.BasicFacilityQuery.currentClickGraphic.symbol.outline.setColor(new Color([255,255,255,0]));
        			this.BasicFacilityQuery.currentClickGraphic.symbol.outline.width=1.3333333333;
        		}
        		for(var i=0;i<graphics.length;i++){
        			if(graphics[i].attributes.objectid == obj.singBaseFacilityId){
        				graphics[i].symbol.outline.setColor(new Color([127,255,0,1]));
        				graphics[i].symbol.outline.width=3;
        				this.BasicFacilityQuery.currentClickGraphic=graphics[i];
        				Global.widgets.mapWidget.map.centerAndZoom(graphics[i].geometry, 11);
        				break;
        			}
        		}
        		this.BasicFacilityQuery.graphicsLayer.redraw();
        	}
        },
        _clearBasicFacilityGraphicsLayer:function(){
        	this.BasicFacilityQuery.graphicsLayer.clear();
        },
        createAuxiliaryline:function(centerPoint){
        	//debugger
        	this.BasicFacilityQuery.auxiliarylineLayer.clear();
        	var radius = this.BasicFacilityQuery.range;
        	var csymbol=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color("rgb(0, 0, 255)"), 2);
        	var arrow1=new PictureMarkerSymbol("gistech/widgets/bufferWidget/images/p1.png",20,20);
    		var arrow2=new PictureMarkerSymbol("gistech/widgets/bufferWidget/images/p2.png",20,20);
    		var arrow3=new PictureMarkerSymbol("gistech/widgets/bufferWidget/images/p3.png",20,20);
        	if(radius/1000 >=1){
        		var cycleCount=(Math.floor(radius/1000)>=3)?3:Math.floor(radius/1000);
        		for(var i=1; i<=cycleCount; i++){
   	     			var circle= new Graphic(new Circle(centerPoint,{"radius": i*1000}),csymbol);//以门店点为中心,r1为半径画圆
   	     			var line,point;
   	     			if(i==1){
   	     				line=new Graphic(new Polyline({paths:[[[centerPoint.x,centerPoint.y],[centerPoint.x+i*1000,centerPoint.y]]],spatialReference:{wkid:3857}}),csymbol);//画水平线
   	     			 	point=new Graphic(new Point(centerPoint.x+i*1000,centerPoint.y,new SpatialReference({ wkid:3857})),arrow1);//画点 该点样式为水平箭头	
   	     			}
   	     			if(i==2){
   	     				line=new Graphic(new Polyline({paths:[[[centerPoint.x,centerPoint.y],[centerPoint.x+(i*1000/2*Math.sqrt(2)),centerPoint.y+(i*1000/2*Math.sqrt(2))]]],spatialReference:{"wkid":3857}}),csymbol);
   	     				point=new Graphic(new Point(centerPoint.x+(i*1000/2*Math.sqrt(2)),centerPoint.y+(i*1000/2*Math.sqrt(2)),new SpatialReference({ wkid:3857})),arrow2);
   	     			}
   	     			if(i==3){
   	     				line=new Graphic(new Polyline({paths:[[[centerPoint.x,centerPoint.y],[centerPoint.x,centerPoint.y+i*1000]]],spatialReference:{"wkid":3857}}),csymbol);
   	     				point=new Graphic(new Point(centerPoint.x,centerPoint.y+i*1000,new SpatialReference({ wkid:3857})),arrow3);
   	     			}
   	     			this.BasicFacilityQuery.auxiliarylineLayer.add(circle);
   	     			this.BasicFacilityQuery.auxiliarylineLayer.add(line);
   	     			this.BasicFacilityQuery.auxiliarylineLayer.add(point);
        		} 
        	}
        },
        _clearBasicFacilityAuxiliarylineLayer:function(){
        	this.BasicFacilityQuery.auxiliarylineLayer.clear();
        },
        setRightToolsPosition:function(){
			var width = $(Global.widgets.right.domNode).width();
    		$(Global.widgets.BottomArrow2.domNode).css("marginRight",width);
    		$(Global.widgets.zoombar.domNode).css("marginRight",width);
    		if(Global.widgets.BottomArrow2.toolbox){
    			$(Global.widgets.BottomArrow2.toolbox.domNode).css("marginRight",width);
    		}
		}
     });
});